<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html>
<head>
    <title>Title</title>
    <%@include file="/WEB-INF/jsp/common.jsp"%>
</head>
<body>
<h2>会员管理</h2>
<hr>
<form action="" class="layui-form">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">成员名称：</label>
            <div class="layui-input-inline">
                <input type="text" id="memberName" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">会员编号：</label>
            <div class="layui-input-inline">
                <input type="text" id="cardMemberId" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <button type="button" class="layui-btn layui-btn-sm" onclick="reloadData();"><i class="layui-icon layui-icon-search"></i> 搜索</button>
        </div>
    </div>
</form>
<table id="memberTable" lay-filter="memberTable"></table>
<script>
    function reloadData(){
        layui.table.reload("memberTable",{
            page:{
                curr : 1
            },
            where : {
                memberName : $("#memberName").val(),
                cardMemberId : $("#cardMemberId").val()
            }
        })
    }

    layui.use(['table','form','laydate'],function () {
        var table= layui.table;
        var form = layui.form;
        //渲染表格
        form.render();

        table.render({
            elem: '#memberTable',
            url: '${path}/menber/list',
            page:true,
            even: true,
            toolbar:'#toolbarDemo',
            cols:[[
                {type:'checkbox'},
                {field:'cardMemberId',title:'编号',width:60},
                {field:'memberName',title:'会员名称',width:100},
                {field:'memberSex',title:'性别',width:60},
                {field:'memberPhone',title:'联系方式',width:130},
                {field:'memberBirthday',title:'出生日期'},
                {field:'membershenfen',title:'身份证',width:150},
                {field:'memberEmail',title:'电子邮件',width:170},
                {field:'cardType',title:'会员卡状态',width:120,templet:function (d){
                        if (d.cardType == 0){
                            return"冻结"
                        }
                        return"正常"}},
                {field:'cardRegDate',title:'建卡时间'},
                {field:'hello',width:120, title:'操作',toolbar:'#barDemo'}
            ]]
        })

        table.on('toolbar(memberTable)',function (obj) {
            var e = obj.event;
            switch (e) {
                case 'add':
                    $.get("${path}/menber/form",function (str) {
                        var index = layer.open({
                            type: 1,
                            title:"添加客户信息",
                            content: str,
                            area: '800px',
                            maxmin: true,
                            btn:['确定','取消'],
                            yes:function (index) {
                                var params = $("#add_member_form").serialize();
                                console.log(params)
                                $.post('${path}/menber/add',params,function () {
                                    table.reload('memberTable');
                                    layer.close(index);
                                })
                            }
                        });
                    })
                    break;
            }
        })

        table.on("tool(memberTable)",function (obj) {
            var data = obj.data;
            var e = obj.event;
            if (e == "edit"){
                $.get("${path}/menber/get",{cardMemberId:data.cardMemberId},function (getstr) {
                    $.get("${path}/menber/form",function (str) {
                        var index = layer.open({
                            type: 1,
                            title:"修改客户信息",
                            content: str,
                            area: '800px',
                            maxmin: true,
                            btn:['确定','取消'],
                            success:function(){
                                form.val('userForm',getstr);
                            },
                            yes:function (index) {
                                var params = $("#add_member_form").serialize();
                                console.log(params)
                                $.post('${path}/menber/edit',params,function () {
                                    table.reload('memberTable');
                                    layer.close(index);
                                })
                            }
                        });
                    })
                })

            }else if (e == "del"){
                layer.open({
                    title: "友情提示",
                    content:"你确定删除吗?",
                    btn:['确定','取消'],
                    yes:function () {
                        $.post("${path}/menber/batchDelete",{ids:data.cardMemberId},function () {
                            layer.msg("删除成功了");
                            table.reload('memberTable');
                        });
                    }
                })
            } else if (e == "dongjie"){
                $.get("${path}/menber/get",{cardMemberId:data.cardMemberId},function (getstr) {

                    if (getstr.cardType == 1){
                        layer.confirm('确定冻结?', {icon: 3, title:'友情提示'}, function(index){
                            $.get("${path}/menber/dongjie",{carType:0,cardMemberId:data.cardMemberId},function (getstr) {
                                layer.msg("冻结成功！",{icon:6})
                                table.reload('memberTable');
                                layer.close(index);
                            })

                        });
                    }else if(getstr.cardType ==0){
                        $.get("${path}/menber/dongjie",{carType:1,cardMemberId:data.cardMemberId},function (getstr) {
                            layer.msg("解冻成功！",{icon:6})
                            table.reload('memberTable');
                            layer.close(index);
                        })
                    }


                })
            }else if (e == "chongzhi"){
                $.get("${path}/cardtraninfo/get",{cardMemberId:data.cardMemberId},function (getstr) {
                    $.get("${path}/menber/chongzhi",function (str) {
                    var index = layer.open({
                        type: 1,
                        title:"充值会员卡",
                        content: str,
                        area: '800px',
                        maxmin: true,
                        btn:['确定','取消'],
                        success:function(){
                            form.val('userForm',getstr);
                        },
                        yes:function (index) {
                            var params = $("#chongzhiform").serialize();

                            console.log(params)

                            $.post('${path}/cardtraninfo/edit',params,function () {
                                table.reload('memberTable');
                                layer.close(index);
                            })
                        }
                    });
                })
                })
            }
        })
    })
</script>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <shiro:hasPermission name="vip:add">
            <button class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon layui-icon-add-circle"></i> 添加</button>
        </shiro:hasPermission>
    </div>
</script>
<script type="text/html" id="barDemo">
    <shiro:hasPermission name="vip:upd">
        <a href="javascript:void(0)" title="修改" lay-event="edit"><i class="layui-icon layui-icon-edit"></i> </a>
    </shiro:hasPermission>
    <shiro:hasPermission name="vip:del">
        <a href="javascript:void(0)"  title="删除" lay-event="del"><i class="layui-icon layui-icon-delete"></i></a>
    </shiro:hasPermission>
    <shiro:hasPermission name="vip:dongjie">
        <a href="javascript:void(0)"  title="冻结/解冻" lay-event="dongjie"><i class="layui-icon layui-icon-diamond"></i></a>
    </shiro:hasPermission>
    <shiro:hasPermission name="vip:chongzhi">
        <a href="javascript:void(0)"  title="充值" lay-event="chongzhi"><i class="layui-icon layui-icon-link"></i></a>
    </shiro:hasPermission>
</script>
</body>
</html>
